//
//  NSError+FWPowerful.m
//  iOSToolkit
//
//  Created by Evan Xie on 3/30/15.
//  Copyright (c) 2015 Family Wings. All rights reserved.
//

#import "NSError+FWPowerful.h"

@implementation NSError (FWPowerful)

+ (NSError *)errorWithErrorDomain:(NSString *)errorDomain
                        errorCode:(NSInteger)errorCode
             localizedDescription:(NSString *)localizedDescription
           localizedFailureReason:(NSString *)localizedFailureReason
{
    if (!localizedFailureReason && !localizedDescription) {
        // Output the message, but we still allow this situation.
        NSLog(@"localizedDescription and localizedFailureReason are nil.");
    }
    
    NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithCapacity:0];
    if (localizedDescription) {
        [userInfo setValue:localizedDescription forKey:NSLocalizedDescriptionKey];
    }
    
    if (localizedFailureReason) {
        [userInfo setValue:localizedFailureReason forKey:NSLocalizedFailureReasonErrorKey];
    }
    
    if (userInfo.count == 0) {
        userInfo = nil;
    }
    
    return [NSError errorWithDomain:errorDomain code:errorCode userInfo:userInfo];
}
@end
